package demo4_8;

import java.util.Arrays;

public class Test {
    //Comparable接口的实使用
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan", 10);
        students[1] = new Student("lisi", 15);
        students[2] = new Student("wangwu", 18);

        System.out.println(Arrays.toString(students));
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }

    public static void main1(String[] args) {
        Student student1 = new Student("zhangsan", 18);
        Student student2 = new Student("lisi", 20);
        //比较student1和student2
        /*
        1.如果student1>student2 返回大于0
        2.如果student1<student2 返回小于0
        3否则返回0相等
        * */
        if (student1.compareTo(student2) > 0) {
            System.out.println("student1 > student2");
        } else {
            System.out.println("student1 <= student2");
        }
    }
}
